<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        img {
            vertical-align: middle;
        }
        
        .smallBox li {
            list-style: none;
            float: left;
            width: 100px;
            height: 60.5px;
        }
        
        .smallBox li img {
            width: 100%;
        }
        
        .imgBox {
            width: 600px;
            position: relative;
        }
        
        .imgBox img {
            width: 600px;
        }
        
        .bigBox {
            width: 400px;
            height: 400px;
            overflow: hidden;
            position: absolute;
            top: 0;
            left: 600px;
        }
        
        .bigBox img {
            position: absolute;
            display: none;
        }
        
        .mask {
            width: 100px;
            height: 100px;
            background-color: rgba(1, 1, 1, .2);
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
    </style>
    <script src="jquery.min.js"></script>
</head>

<body>
    <div class="box">
        <div class="imgBox">
            <img src="images/placeholder.jpg" alt="">
            <div class="mask"></div>
        </div>
        <ul class="smallBox">
            <li abc="images/1.jpg"><img src="images/1-small.jpg" alt=""></li>
            <li abc="images/2.jpg"><img src="images/2-small.jpg" alt=""></li>
            <li abc="images/3.jpg"><img src="images/3-small.jpg" alt=""></li>
            <li abc="images/4.jpg"><img src="images/4-small.jpg" alt=""></li>
            <li abc="images/5.jpg"><img src="images/5-small.jpg" alt=""></li>
        </ul>
        <div class="bigBox">
            <img src="" alt="">
        </div>
    </div>
</body>
<script>
    $(function() {
        $('li').hover(function() {
            $('.imgBox img').attr('src', $(this).attr('abc'))
            $('.bigBox img').attr('src', $(this).attr('abc'))
        })
        $('.imgBox').hover(function() {
            $('.bigBox img').show()
            $('.mask').show()
            console.log(1);
        }, function() {
            $('.mask').hide()
            $('.bigBox img').hide()
            console.log(2);
        })
        $('.imgBox').mousemove(function(e) {
            let x = e.clientX - $('.mask').width() / 2 - $(this).offset().left;
            let y = e.clientY - $('.mask').height() / 2 - $(this).offset().top;
            // 判断边界
            x = x < 0 ? 0 : x;
            y = y < 0 ? 0 : y;
            x = x > $('.imgBox').width() - $('.mask').width() ? $('.imgBox').width() - $('.mask').width() : x;
            y = y > $('.imgBox').height() - $('.mask').height() ? $('.imgBox').height() - $('.mask').height() : y;
            // 赋值
            $('.mask').css({
                    top: y,
                    left: x
                })
                // 操作大图
            let targetX = x / ($('.imgBox').width() - $('.mask').width()) * ($('.bigBox img').width() - $('.bigBox').width())
            let targetY = y / ($('.imgBox').height() - $('.mask').height()) * ($('.bigBox img').height() - $('.bigBox').height())
            $('.bigBox img').css({
                top: -targetY,
                left: -targetX
            })
        })
    })
</script>

</html>